SHL github project: uat_shl

  • training module: shl_tm

  • prediction module: shl_pm

  • simulation module: shl_sm

  • misc module: shl_mm

data feeds:

  • historical bidding price, per second, time series

  • live bidding price, per second, time series

parameter lookup table: python dictionary

  • parm_si (seasonality index per second)

  • parm_month (parameter like alpha, beta, gamma, etc. per month)


In [27]:
%matplotlib inline
import matplotlib.pyplot as plt

In [1]:
import pandas as pd

Read raw data


In [2]:
df_history_ts_process = pd.read_csv('data/history_ts.csv') 
df_history_ts_process.tail()


Out[2]:
ccyy-mm time bid-price ref-price
1886 2017-07 11:29:56 92100 89800
1887 2017-07 11:29:57 92100 89800
1888 2017-07 11:29:58 92100 89800
1889 2017-07 11:29:59 92200 89800
1890 2017-07 11:30:00 92200 89800

In [3]:
df_history_table_process = pd.read_csv('data/history_table.csv') 
df_history_table_process.tail()


Out[3]:
ccyy-mm volume-plate deal-price-low deal-price-avg deal-early-second volume-bidder
26 2017-03 10356 87800 87916 55 262010
27 2017-04 12196 89800 89850 59 252273
28 2017-05 10316 90100 90209 55 270197
29 2017-06 10312 89400 89532 45 244349
30 2017-07 10325 92200 92250 57 269189

In [6]:
df_parm_si = pd.read_csv('data/parm_si.csv') 
# print(df_parm_si[(df_parm_si['ccyy-mm'] == '2017-07') & (df_parm_si['time'] == '11:29:00')].iloc[0]['si'])
df_parm_si.tail()


Out[6]:
ccyy-mm time si
2191 2017-12 11:29:56 1.0
2192 2017-12 11:29:57 1.0
2193 2017-12 11:29:58 1.0
2194 2017-12 11:29:59 1.0
2195 2017-12 11:30:00 1.0

In [7]:
df_parm_month = pd.read_csv('data/parm_month.csv') 
# print(df_parm_month[(df_parm_month['ccyy-mm'] == '2017-07') & (df_parm_month['time'] == '11:29:00')].iloc[0]['di'])
df_parm_month.tail()


Out[7]:
ccyy-mm time alpha beta gamma sec57-weight month-weight short-weight direction di
67 2020-08 11:29:00 0.5 0.5 0.5 0.5 0.9 0.125 -1 300
68 2020-09 11:29:00 0.5 0.5 0.5 0.5 0.9 0.125 -1 300
69 2020-10 11:29:00 0.5 0.5 0.5 0.5 0.9 0.125 -1 300
70 2020-11 11:29:00 0.5 0.5 0.5 0.5 0.9 0.125 -1 300
71 2020-12 11:29:00 0.5 0.5 0.5 0.5 0.9 0.125 -1 300

Initialization


In [8]:
# function to fetch Seasonality-Index
def fetech_si(ccyy_mm, time, df_parm_si):
#     return df_parm_si[(df_parm_si['ccyy-mm'] == '2017-09') & (df_parm_si['time'] == '11:29:00')]
    return df_parm_si[(df_parm_si['ccyy-mm'] == ccyy_mm) & (df_parm_si['time'] == time)].iloc[0]['si']

In [9]:
# function to fetch Dynamic-Increment
def fetech_di(ccyy_mm, df_parm_month):
#     print(df_parm_month[df_parm_month['ccyy-mm'] == '2017-07'].iloc[0]['di'])
    return df_parm_month[df_parm_month['ccyy-mm'] == ccyy_mm].iloc[0]['di']

In [62]:
def get_previous_n_sec_time_as_str(df_time_field, n):
    return str((pd.to_datetime(df_time_field, format='%H:%M:%S') - pd.Timedelta(seconds=n)).time())
# print(get_previous_n_sec_time_as_str('11:29:57',3))

def get_future_n_sec_time_as_str(df_time_field, n):
    return str((pd.to_datetime(df_time_field, format='%H:%M:%S') - pd.Timedelta(seconds=-n)).time())
# print(get_future_n_sec_time_as_str('11:29:57',3))


11:29:54
11:30:00

In [ ]:


In [42]:
# which month to predict?
global_parm_ccyy_mm = '2017-07' 

# create global base price
global_parm_base_price = 10000000

# create predictino results dataframe: shl_pm
# df_shl_pm = pd.DataFrame()

global_parm_dynamic_increment = fetech_di(global_parm_ccyy_mm, df_parm_month)

global_parm_alpha = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['alpha']
global_parm_beta  = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['beta']
global_parm_gamma = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['gamma']
global_parm_sec57_weight = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['sec57-weight']
global_parm_month_weight = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['month-weight']
global_parm_short_weight = df_parm_month[df_parm_month['ccyy-mm'] == global_parm_ccyy_mm].iloc[0]['short-weight']

print('=================================================')
print('  Global Parameters for Month : %s' % global_parm_ccyy_mm)
print('-------------------------------------------------')

print('global_parm_dynamic_increment : %d' % global_parm_dynamic_increment)

print('global_parm_alpha             : %0.15f' % global_parm_alpha) # used in forecasting
print('global_parm_beta              : %0.15f' % global_parm_beta)  # used in forecasting
print('global_parm_gamma             : %0.15f' % global_parm_gamma) # used in forecasting
print('global_parm_sec57_weight      : %f' % global_parm_sec57_weight) # used in training a model
print('global_parm_month_weight      : %f' % global_parm_month_weight) # used in training a model
print('global_parm_short_weight      : %f' % global_parm_short_weight) # used in training a model
print('=================================================')

# plot seasonality index
# print(df_parm_si[(df_parm_si['ccyy-mm'] == '2017-07')]['si'])
plt.figure(figsize=(6,3))
plt.plot(df_parm_si[(df_parm_si['ccyy-mm'] == '2017-07')]['si'])


=================================================
  Global Parameters for Month : 2017-07
-------------------------------------------------
global_parm_dynamic_increment : 300
global_parm_alpha             : 0.642332134767631
global_parm_beta              : 0.230274892614982
global_parm_gamma             : 0.218044289515065
global_parm_sec57_weight      : 0.500000
global_parm_month_weight      : 0.900000
global_parm_short_weight      : 0.125000
=================================================
Out[42]:
[<matplotlib.lines.Line2D at 0x7f97420387f0>]

In [ ]:

Start of shl_sm


In [154]:
# 11:29:00~11:29:50

for i in range(1830, 1830+51): # use July 2015 data as simulatino
    print('\n<<<< Record No.: %5d >>>>' % i)
    print(df_history_ts_process['ccyy-mm'][i]) # format: ccyy-mm
    print(df_history_ts_process['time'][i]) # format: hh:mm:ss
    print(df_history_ts_process['bid-price'][i]) # format: integer
#     print(df_history_ts_process['ref-price'][i])
    
    # capture & calculate 11:29:00 bid price - 1 = base price
    if df_history_ts_process['time'][i] == '11:29:00':
        global_parm_base_price = df_history_ts_process['bid-price'][i] -1 
        print('#### global_parm_base_price : %d ####' % global_parm_base_price)

        
    print('---- Pre-Process ---')
    # pre-process: ccyy-mm-hh:mm:ss
    current_datetime = df_history_ts_process['ccyy-mm'][i] + ' ' + df_history_ts_process['time'][i]
    current_price4pm = df_history_ts_process['bid-price'][i] -  global_parm_base_price
    print('#### current_datetime   : %s ####' %  current_datetime)
    print('#### current_price4pm   : %d ####' % current_price4pm)
    
    # get Seasonality-Index
    current_si = fetech_si(df_history_ts_process['ccyy-mm'][i]
                                         ,df_history_ts_process['time'][i]
                                         ,df_parm_si)
    print('#### current_si         : %0.10f ####' %  current_si)
    # get de-seasoned price: price4pmsi
    current_price4pmsi = current_price4pm / current_si
    print('#### current_price4pmsi : %0.10f ####' % current_price4pmsi)
    


    if df_history_ts_process['time'][i] == '11:29:00':
        df_shl_pm = pd.DataFrame() # initialize prediction dataframe at 11:29:00
        print('---- call predicitno function shl_pm ---- %s' % df_history_ts_process['time'][i])
        current_pred_les_level = current_price4pmsi
        current_pred_les_trend = 0
        current_pred_les = current_pred_les_level + current_pred_les_trend
        current_pred_les_misc = 0
        current_pred_price = (current_pred_les + current_pred_les_misc) * current_si \
                                + global_parm_base_price
        current_pred_price_rounded = round(current_pred_price/100, 0) * 100
        current_pred_dynamic_increment = global_parm_dynamic_increment
        current_pred_set_price_rounded = current_pred_price_rounded + current_pred_dynamic_increment
    else:
#         call predicitno functino shl_pm, forcaste next k=1 step
        print('---- call predicitno function shl_pm ---- %s' % df_history_ts_process['time'][i])
        previous_time = get_previous_n_sec_time_as_str(df_history_ts_process['time'][i], 1)
        previous_pred_les_level = df_shl_pm[(df_shl_pm['ccyy-mm'] == df_history_ts_process['ccyy-mm'][i]) \
                                            & (df_shl_pm['time'] ==previous_time)].iloc[0]['pred_les_level']
        print('     previous_pred_les_level : %f' % previous_pred_les_level)
        
        previous_pred_les_trend = df_shl_pm[(df_shl_pm['ccyy-mm'] == df_history_ts_process['ccyy-mm'][i]) \
                                            & (df_shl_pm['time'] ==previous_time)].iloc[0]['pred_les_trend']
        print('     previous_pred_les_trend : %f' % previous_pred_les_trend)
        
        current_pred_les_level = global_parm_alpha * current_price4pmsi \
                                    + (1 - global_parm_alpha) * (previous_pred_les_level + previous_pred_les_trend)
        print('     current_pred_les_level  : %f' % current_pred_les_level)
        current_pred_les_trend = global_parm_beta * (current_pred_les_level - previous_pred_les_level) \
                                    + (1 - global_parm_beta) * previous_pred_les_trend
        print('     current_pred_les_trend  : %f' % current_pred_les_trend)
        current_pred_les = current_pred_les_level + current_pred_les_trend
        current_pred_les_misc = 0
        current_pred_price = (current_pred_les + current_pred_les_misc) * current_si \
                                + global_parm_base_price
        current_pred_price_rounded = round(current_pred_price/100, 0) * 100
        current_pred_dynamic_increment = global_parm_dynamic_increment
        current_pred_set_price_rounded = current_pred_price_rounded + current_pred_dynamic_increment
   
        
    # write results to shl_pm dataframe
            
    df_shl_pm_current = {
                         'ccyy-mm' : df_history_ts_process['ccyy-mm'][i]
                        ,'time' : df_history_ts_process['time'][i]
                        ,'bid' : df_history_ts_process['bid-price'][i]
                        ,'datetime' : current_datetime
                        ,'price4pm' : current_price4pm
                        ,'si' : current_si
                        ,'price4pmsi' :  current_price4pmsi
                        ,'pred_les_level' : current_pred_les_level
                        ,'pred_les_trend' : current_pred_les_trend
                        ,'current_pred_les' : current_pred_les
                        ,'pred_les_misc' : current_pred_les_misc
                        ,'pred_price' : current_pred_price
                        ,'pred_price_rounded' : current_pred_price_rounded
                        ,'pred_dynamic_increment' : current_pred_dynamic_increment # +200 or + 300
                        ,'pred_set_price_rounded' : current_pred_set_price_rounded
                        }
    df_shl_pm =  df_shl_pm.append(df_shl_pm_current, ignore_index=True)


<<<< Record No.:  1830 >>>>
2017-07
11:29:00
90400
#### global_parm_base_price : 90399 ####
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:00 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0023669570 ####
#### current_price4pmsi : 422.4833826724 ####
---- call predicitno function shl_pm ---- 11:29:00

<<<< Record No.:  1831 >>>>
2017-07
11:29:01
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:01 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0223882810 ####
#### current_price4pmsi : 44.6662251559 ####
---- call predicitno function shl_pm ---- 11:29:01
     previous_pred_les_level : 422.483383
     previous_pred_les_trend : 0.000000
     current_pred_les_level  : 179.799281
     current_pred_les_trend  : -55.884055

<<<< Record No.:  1832 >>>>
2017-07
11:29:02
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:02 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0309107700 ####
#### current_price4pmsi : 32.3511837460 ####
---- call predicitno function shl_pm ---- 11:29:02
     previous_pred_les_level : 179.799281
     previous_pred_les_trend : -55.884055
     current_pred_les_level  : 65.100699
     current_pred_les_trend  : -69.427564

<<<< Record No.:  1833 >>>>
2017-07
11:29:03
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:03 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0377696020 ####
#### current_price4pmsi : 26.4763181778 ####
---- call predicitno function shl_pm ---- 11:29:03
     previous_pred_les_level : 65.100699
     previous_pred_les_trend : -69.427564
     current_pred_les_level  : 15.459009
     current_pred_les_trend  : -64.871374

<<<< Record No.:  1834 >>>>
2017-07
11:29:04
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:04 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0457052300 ####
#### current_price4pmsi : 21.8793341594 ####
---- call predicitno function shl_pm ---- 11:29:04
     previous_pred_les_level : 15.459009
     previous_pred_les_trend : -64.871374
     current_pred_les_level  : -3.619416
     current_pred_les_trend  : -54.326408

<<<< Record No.:  1835 >>>>
2017-07
11:29:05
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:05 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0452799070 ####
#### current_price4pmsi : 22.0848510135 ####
---- call predicitno function shl_pm ---- 11:29:05
     previous_pred_les_level : -3.619416
     previous_pred_les_trend : -54.326408
     current_pred_les_level  : -6.539549
     current_pred_les_trend  : -42.488833

<<<< Record No.:  1836 >>>>
2017-07
11:29:06
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:06 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0807556680 ####
#### current_price4pmsi : 12.3830317396 ####
---- call predicitno function shl_pm ---- 11:29:06
     previous_pred_les_level : -6.539549
     previous_pred_les_trend : -42.488833
     current_pred_les_level  : -9.581858
     current_pred_les_trend  : -33.405289

<<<< Record No.:  1837 >>>>
2017-07
11:29:07
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:07 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.0985017130 ####
#### current_price4pmsi : 10.1521077100 ####
---- call predicitno function shl_pm ---- 11:29:07
     previous_pred_les_level : -9.581858
     previous_pred_les_trend : -33.405289
     current_pred_les_level  : -8.854096
     current_pred_les_trend  : -25.545305

<<<< Record No.:  1838 >>>>
2017-07
11:29:08
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:08 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.1361543100 ####
#### current_price4pmsi : 7.3446077469 ####
---- call predicitno function shl_pm ---- 11:29:08
     previous_pred_les_level : -8.854096
     previous_pred_les_trend : -25.545305
     current_pred_les_level  : -7.585883
     current_pred_les_trend  : -19.370825

<<<< Record No.:  1839 >>>>
2017-07
11:29:09
90400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:09 ####
#### current_price4pm   : 1 ####
#### current_si         : 0.2041642360 ####
#### current_price4pmsi : 4.8980174961 ####
---- call predicitno function shl_pm ---- 11:29:09
     previous_pred_les_level : -7.585883
     previous_pred_les_trend : -19.370825
     current_pred_les_level  : -6.495394
     current_pred_les_trend  : -14.659098

<<<< Record No.:  1840 >>>>
2017-07
11:29:10
90500
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:10 ####
#### current_price4pm   : 101 ####
#### current_si         : 0.2310771670 ####
#### current_price4pmsi : 437.0834267671 ####
---- call predicitno function shl_pm ---- 11:29:10
     previous_pred_les_level : -6.495394
     previous_pred_les_trend : -14.659098
     current_pred_les_level  : 273.186449
     current_pred_les_trend  : 53.120231

<<<< Record No.:  1841 >>>>
2017-07
11:29:11
90500
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:11 ####
#### current_price4pm   : 101 ####
#### current_si         : 0.2910254840 ####
#### current_price4pmsi : 347.0486454032 ####
---- call predicitno function shl_pm ---- 11:29:11
     previous_pred_les_level : 273.186449
     previous_pred_les_trend : 53.120231
     current_pred_les_level  : 339.629911
     current_pred_les_trend  : 56.188236

<<<< Record No.:  1842 >>>>
2017-07
11:29:12
90500
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:12 ####
#### current_price4pm   : 101 ####
#### current_si         : 0.3431273480 ####
#### current_price4pmsi : 294.3513555206 ####
---- call predicitno function shl_pm ---- 11:29:12
     previous_pred_les_level : 339.629911
     previous_pred_les_trend : 56.188236
     current_pred_les_level  : 330.642766
     current_pred_les_trend  : 41.179982

<<<< Record No.:  1843 >>>>
2017-07
11:29:13
90600
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:13 ####
#### current_price4pm   : 201 ####
#### current_si         : 0.3510740950 ####
#### current_price4pmsi : 572.5287136324 ####
---- call predicitno function shl_pm ---- 11:29:13
     previous_pred_les_level : 330.642766
     previous_pred_les_trend : 41.179982
     current_pred_les_level  : 500.742640
     current_pred_les_trend  : 70.866997

<<<< Record No.:  1844 >>>>
2017-07
11:29:14
90600
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:14 ####
#### current_price4pm   : 201 ####
#### current_si         : 0.3706555480 ####
#### current_price4pmsi : 542.2824535733 ####
---- call predicitno function shl_pm ---- 11:29:14
     previous_pred_les_level : 500.742640
     previous_pred_les_trend : 70.866997
     current_pred_les_level  : 552.771844
     current_pred_les_trend  : 66.529126

<<<< Record No.:  1845 >>>>
2017-07
11:29:15
90600
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:15 ####
#### current_price4pm   : 201 ####
#### current_si         : 0.4011467510 ####
#### current_price4pmsi : 501.0635122905 ####
---- call predicitno function shl_pm ---- 11:29:15
     previous_pred_les_level : 552.771844
     previous_pred_les_trend : 66.529126
     current_pred_les_level  : 543.353252
     current_pred_les_trend  : 49.040273

<<<< Record No.:  1846 >>>>
2017-07
11:29:16
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:16 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.4120902590 ####
#### current_price4pmsi : 730.4225067839 ####
---- call predicitno function shl_pm ---- 11:29:16
     previous_pred_les_level : 543.353252
     previous_pred_les_trend : 49.040273
     current_pred_les_level  : 681.053975
     current_pred_les_trend  : 69.456549

<<<< Record No.:  1847 >>>>
2017-07
11:29:17
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:17 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.4535685080 ####
#### current_price4pmsi : 663.6263203705 ####
---- call predicitno function shl_pm ---- 11:29:17
     previous_pred_les_level : 681.053975
     previous_pred_les_trend : 69.456549
     current_pred_les_level  : 694.702008
     current_pred_les_trend  : 56.605249

<<<< Record No.:  1848 >>>>
2017-07
11:29:18
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:18 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.4836754840 ####
#### current_price4pmsi : 622.3180830062 ####
---- call predicitno function shl_pm ---- 11:29:18
     previous_pred_les_level : 694.702008
     previous_pred_les_trend : 56.605249
     current_pred_les_level  : 668.453366
     current_pred_les_trend  : 37.526078

<<<< Record No.:  1849 >>>>
2017-07
11:29:19
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:19 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.5045423610 ####
#### current_price4pmsi : 596.5802344196 ####
---- call predicitno function shl_pm ---- 11:29:19
     previous_pred_les_level : 668.453366
     previous_pred_les_trend : 37.526078
     current_pred_les_level  : 635.708816
     current_pred_les_trend  : 21.344517

<<<< Record No.:  1850 >>>>
2017-07
11:29:20
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:20 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.5273150370 ####
#### current_price4pmsi : 570.8162651921 ####
---- call predicitno function shl_pm ---- 11:29:20
     previous_pred_les_level : 635.708816
     previous_pred_les_trend : 21.344517
     current_pred_les_level  : 601.660493
     current_pred_les_trend  : 8.588937

<<<< Record No.:  1851 >>>>
2017-07
11:29:21
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:21 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.5666965740 ####
#### current_price4pmsi : 531.1484378234 ####
---- call predicitno function shl_pm ---- 11:29:21
     previous_pred_les_level : 601.660493
     previous_pred_les_trend : 8.588937
     current_pred_les_level  : 559.440321
     current_pred_les_trend  : -3.111126

<<<< Record No.:  1852 >>>>
2017-07
11:29:22
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:22 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.5783832890 ####
#### current_price4pmsi : 520.4161422444 ####
---- call predicitno function shl_pm ---- 11:29:22
     previous_pred_les_level : 559.440321
     previous_pred_les_trend : -3.111126
     current_pred_les_level  : 533.261087
     current_pred_les_trend  : -8.423132

<<<< Record No.:  1853 >>>>
2017-07
11:29:23
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:23 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.5903581650 ####
#### current_price4pmsi : 509.8599762739 ####
---- call predicitno function shl_pm ---- 11:29:23
     previous_pred_les_level : 533.261087
     previous_pred_les_trend : -8.423132
     current_pred_les_level  : 515.217118
     current_pred_les_trend  : -10.638569

<<<< Record No.:  1854 >>>>
2017-07
11:29:24
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:24 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.6203383340 ####
#### current_price4pmsi : 485.2190869120 ####
---- call predicitno function shl_pm ---- 11:29:24
     previous_pred_les_level : 515.217118
     previous_pred_les_trend : -10.638569
     current_pred_les_level  : 492.143344
     current_pred_les_trend  : -13.502084

<<<< Record No.:  1855 >>>>
2017-07
11:29:25
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:25 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.6624022500 ####
#### current_price4pmsi : 454.4066690595 ####
---- call predicitno function shl_pm ---- 11:29:25
     previous_pred_les_level : 492.143344
     previous_pred_les_trend : -13.502084
     current_pred_les_level  : 463.074603
     current_pred_les_trend  : -17.086695

<<<< Record No.:  1856 >>>>
2017-07
11:29:26
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:26 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.6803182270 ####
#### current_price4pmsi : 442.4400053594 ####
---- call predicitno function shl_pm ---- 11:29:26
     previous_pred_les_level : 463.074603
     previous_pred_les_trend : -17.086695
     current_pred_les_level  : 443.708976
     current_pred_les_trend  : -17.611475

<<<< Record No.:  1857 >>>>
2017-07
11:29:27
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:27 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.7013944910 ####
#### current_price4pmsi : 429.1450871974 ####
---- call predicitno function shl_pm ---- 11:29:27
     previous_pred_les_level : 443.708976
     previous_pred_les_trend : -17.611475
     current_pred_les_level  : 428.055064
     current_pred_les_trend  : -17.160698

<<<< Record No.:  1858 >>>>
2017-07
11:29:28
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:28 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.7261122680 ####
#### current_price4pmsi : 414.5364474134 ####
---- call predicitno function shl_pm ---- 11:29:28
     previous_pred_les_level : 428.055064
     previous_pred_les_trend : -17.160698
     current_pred_les_level  : 413.233792
     current_pred_les_trend  : -16.621987

<<<< Record No.:  1859 >>>>
2017-07
11:29:29
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:29 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.7412284280 ####
#### current_price4pmsi : 406.0826442021 ####
---- call predicitno function shl_pm ---- 11:29:29
     previous_pred_les_level : 413.233792
     previous_pred_les_trend : -16.621987
     current_pred_les_level  : 402.695229
     current_pred_les_trend  : -15.221127

<<<< Record No.:  1860 >>>>
2017-07
11:29:30
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:30 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.7848751150 ####
#### current_price4pmsi : 383.5005012231 ####
---- call predicitno function shl_pm ---- 11:29:30
     previous_pred_les_level : 402.695229
     previous_pred_les_trend : -15.221127
     current_pred_les_level  : 384.921731
     current_pred_les_trend  : -15.808874

<<<< Record No.:  1861 >>>>
2017-07
11:29:31
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:31 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.7883406290 ####
#### current_price4pmsi : 381.8146482972 ####
---- call predicitno function shl_pm ---- 11:29:31
     previous_pred_les_level : 384.921731
     previous_pred_les_trend : -15.808874
     current_pred_les_level  : 377.271626
     current_pred_les_trend  : -13.930114

<<<< Record No.:  1862 >>>>
2017-07
11:29:32
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:32 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.8143918490 ####
#### current_price4pmsi : 369.6009486952 ####
---- call predicitno function shl_pm ---- 11:29:32
     previous_pred_les_level : 377.271626
     previous_pred_les_trend : -13.930114
     current_pred_les_level  : 367.362149
     current_pred_les_trend  : -13.004262

<<<< Record No.:  1863 >>>>
2017-07
11:29:33
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:33 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.8351005610 ####
#### current_price4pmsi : 360.4356338111 ####
---- call predicitno function shl_pm ---- 11:29:33
     previous_pred_les_level : 367.362149
     previous_pred_les_trend : -13.004262
     current_pred_les_level  : 358.261819
     current_pred_les_trend  : -12.105285

<<<< Record No.:  1864 >>>>
2017-07
11:29:34
90700
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:34 ####
#### current_price4pm   : 301 ####
#### current_si         : 0.8670445380 ####
#### current_price4pmsi : 347.1563302784 ####
---- call predicitno function shl_pm ---- 11:29:34
     previous_pred_les_level : 358.261819
     previous_pred_les_trend : -12.105285
     current_pred_les_level  : 346.798735
     current_pred_les_trend  : -11.957402

<<<< Record No.:  1865 >>>>
2017-07
11:29:35
90800
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:35 ####
#### current_price4pm   : 401 ####
#### current_si         : 0.9216129500 ####
#### current_price4pmsi : 435.1067332550 ####
---- call predicitno function shl_pm ---- 11:29:35
     previous_pred_les_level : 346.798735
     previous_pred_les_trend : -11.957402
     current_pred_les_level  : 399.245022
     current_pred_les_trend  : 2.873150

<<<< Record No.:  1866 >>>>
2017-07
11:29:36
90800
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:36 ####
#### current_price4pm   : 401 ####
#### current_si         : 0.9539289700 ####
#### current_price4pmsi : 420.3667281433 ####
---- call predicitno function shl_pm ---- 11:29:36
     previous_pred_les_level : 399.245022
     previous_pred_les_trend : 2.873150
     current_pred_les_level  : 413.839806
     current_pred_les_trend  : 5.572348

<<<< Record No.:  1867 >>>>
2017-07
11:29:37
90900
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:37 ####
#### current_price4pm   : 501 ####
#### current_si         : 0.9779660700 ####
#### current_price4pmsi : 512.2877115767 ####
---- call predicitno function shl_pm ---- 11:29:37
     previous_pred_les_level : 413.839806
     previous_pred_les_trend : 5.572348
     current_pred_les_level  : 479.069109
     current_pred_les_trend  : 19.309847

<<<< Record No.:  1868 >>>>
2017-07
11:29:38
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:38 ####
#### current_price4pm   : 601 ####
#### current_si         : 0.9935136330 ####
#### current_price4pmsi : 604.9237574982 ####
---- call predicitno function shl_pm ---- 11:29:38
     previous_pred_les_level : 479.069109
     previous_pred_les_trend : 19.309847
     current_pred_les_level  : 566.816106
     current_pred_les_trend  : 35.069205

<<<< Record No.:  1869 >>>>
2017-07
11:29:39
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:39 ####
#### current_price4pm   : 601 ####
#### current_si         : 1.0325517050 ####
#### current_price4pmsi : 582.0531766978 ####
---- call predicitno function shl_pm ---- 11:29:39
     previous_pred_les_level : 566.816106
     previous_pred_les_trend : 35.069205
     current_pred_les_level  : 589.146494
     current_pred_les_trend  : 32.135775

<<<< Record No.:  1870 >>>>
2017-07
11:29:40
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:40 ####
#### current_price4pm   : 601 ####
#### current_si         : 1.0762695320 ####
#### current_price4pmsi : 558.4103072055 ####
---- call predicitno function shl_pm ---- 11:29:40
     previous_pred_les_level : 589.146494
     previous_pred_les_trend : 32.135775
     current_pred_les_level  : 580.897587
     current_pred_les_trend  : 22.836197

<<<< Record No.:  1871 >>>>
2017-07
11:29:41
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:41 ####
#### current_price4pm   : 601 ####
#### current_si         : 1.1032848210 ####
#### current_price4pmsi : 544.7369424110 ####
---- call predicitno function shl_pm ---- 11:29:41
     previous_pred_les_level : 580.897587
     previous_pred_les_trend : 22.836197
     current_pred_les_level  : 565.838217
     current_pred_les_trend  : 14.109799

<<<< Record No.:  1872 >>>>
2017-07
11:29:42
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:42 ####
#### current_price4pm   : 601 ####
#### current_si         : 1.1629896100 ####
#### current_price4pmsi : 516.7715986732 ####
---- call predicitno function shl_pm ---- 11:29:42
     previous_pred_les_level : 565.838217
     previous_pred_les_trend : 14.109799
     current_pred_les_level  : 539.367773
     current_pred_les_trend  : 4.765188

<<<< Record No.:  1873 >>>>
2017-07
11:29:43
91000
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:43 ####
#### current_price4pm   : 601 ####
#### current_si         : 1.2717913130 ####
#### current_price4pmsi : 472.5618062151 ####
---- call predicitno function shl_pm ---- 11:29:43
     previous_pred_les_level : 539.367773
     previous_pred_les_trend : 4.765188
     current_pred_les_level  : 498.160508
     current_pred_les_trend  : -5.821114

<<<< Record No.:  1874 >>>>
2017-07
11:29:44
91100
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:44 ####
#### current_price4pm   : 701 ####
#### current_si         : 1.3866613510 ####
#### current_price4pmsi : 505.5307840624 ####
---- call predicitno function shl_pm ---- 11:29:44
     previous_pred_les_level : 498.160508
     previous_pred_les_trend : -5.821114
     current_pred_les_level  : 500.812648
     current_pred_les_trend  : -3.869936

<<<< Record No.:  1875 >>>>
2017-07
11:29:45
91100
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:45 ####
#### current_price4pm   : 701 ####
#### current_si         : 1.4370894140 ####
#### current_price4pmsi : 487.7914993813 ####
---- call predicitno function shl_pm ---- 11:29:45
     previous_pred_les_level : 500.812648
     previous_pred_les_trend : -3.869936
     current_pred_les_level  : 491.064594
     current_pred_les_trend  : -5.223519

<<<< Record No.:  1876 >>>>
2017-07
11:29:46
91200
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:46 ####
#### current_price4pm   : 801 ####
#### current_si         : 1.5686206330 ####
#### current_price4pmsi : 510.6397194764 ####
---- call predicitno function shl_pm ---- 11:29:46
     previous_pred_les_level : 491.064594
     previous_pred_les_trend : -5.223519
     current_pred_les_level  : 501.770041
     current_pred_les_trend  : -1.555478

<<<< Record No.:  1877 >>>>
2017-07
11:29:47
91300
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:47 ####
#### current_price4pm   : 901 ####
#### current_si         : 1.6413910300 ####
#### current_price4pmsi : 548.9246520374 ####
---- call predicitno function shl_pm ---- 11:29:47
     previous_pred_les_level : 501.770041
     previous_pred_les_trend : -1.555478
     current_pred_les_level  : 531.502619
     current_pred_les_trend  : 5.649376

<<<< Record No.:  1878 >>>>
2017-07
11:29:48
91400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:48 ####
#### current_price4pm   : 1001 ####
#### current_si         : 1.7490712830 ####
#### current_price4pmsi : 572.3037189674 ####
---- call predicitno function shl_pm ---- 11:29:48
     previous_pred_les_level : 531.502619
     previous_pred_les_trend : 5.649376
     current_pred_les_level  : 559.731077
     current_pred_les_trend  : 10.848771

<<<< Record No.:  1879 >>>>
2017-07
11:29:49
91400
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:49 ####
#### current_price4pm   : 1001 ####
#### current_si         : 1.7897347710 ####
#### current_price4pmsi : 559.3007501557 ####
---- call predicitno function shl_pm ---- 11:29:49
     previous_pred_les_level : 559.731077
     previous_pred_les_trend : 10.848771
     current_pred_les_level  : 563.334921
     current_pred_les_trend  : 9.180447

<<<< Record No.:  1880 >>>>
2017-07
11:29:50
91500
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:50 ####
#### current_price4pm   : 1101 ####
#### current_si         : 1.9329318490 ####
#### current_price4pmsi : 569.6010444288 ####
---- call predicitno function shl_pm ---- 11:29:50
     previous_pred_les_level : 563.334921
     previous_pred_les_trend : 9.180447
     current_pred_les_level  : 570.643404
     current_pred_les_trend  : 8.749380

In [155]:
df_shl_pm.head()


Out[155]:
bid ccyy-mm current_pred_les datetime pred_dynamic_increment pred_les_level pred_les_misc pred_les_trend pred_price pred_price_rounded pred_set_price_rounded price4pm price4pmsi si time
0 90400.0 2017-07 422.483383 2017-07 11:29:00 300.0 422.483383 0.0 0.000000 90400.000000 90400.0 90700.0 1.0 422.483383 0.002367 11:29:00
1 90400.0 2017-07 123.915226 2017-07 11:29:01 300.0 179.799281 0.0 -55.884055 90401.774249 90400.0 90700.0 1.0 44.666225 0.022388 11:29:01
2 90400.0 2017-07 -4.326865 2017-07 11:29:02 300.0 65.100699 0.0 -69.427564 90398.866253 90400.0 90700.0 1.0 32.351184 0.030911 11:29:02
3 90400.0 2017-07 -49.412365 2017-07 11:29:03 300.0 15.459009 0.0 -64.871374 90397.133715 90400.0 90700.0 1.0 26.476318 0.037770 11:29:03
4 90400.0 2017-07 -57.945823 2017-07 11:29:04 300.0 -3.619416 0.0 -54.326408 90396.351573 90400.0 90700.0 1.0 21.879334 0.045705 11:29:04

In [157]:
df_shl_pm.tail()


Out[157]:
bid ccyy-mm current_pred_les datetime pred_dynamic_increment pred_les_level pred_les_misc pred_les_trend pred_price pred_price_rounded pred_set_price_rounded price4pm price4pmsi si time
46 91200.0 2017-07 500.214563 2017-07 11:29:46 300.0 501.770041 0.0 -1.555478 91183.646885 91200.0 91500.0 801.0 510.639719 1.568621 11:29:46
47 91300.0 2017-07 537.151994 2017-07 11:29:47 300.0 531.502619 0.0 5.649376 91280.676465 91300.0 91600.0 901.0 548.924652 1.641391 11:29:47
48 91400.0 2017-07 570.579848 2017-07 11:29:48 300.0 559.731077 0.0 10.848771 91396.984827 91400.0 91700.0 1001.0 572.303719 1.749071 11:29:48
49 91400.0 2017-07 572.515368 2017-07 11:29:49 300.0 563.334921 0.0 9.180447 91423.650660 91400.0 91700.0 1001.0 559.300750 1.789735 11:29:49
50 91500.0 2017-07 579.392785 2017-07 11:29:50 300.0 570.643404 0.0 8.749380 91518.926766 91500.0 91800.0 1101.0 569.601044 1.932932 11:29:50

In [124]:
plt.figure(figsize=(12,6))
plt.plot(df_shl_pm['bid'])
# plt.plot(df_shl_pm['pred_price'])
plt.plot(df_shl_pm['pred_price'].shift(1))
# plt.plot(df_shl_pm['pred_price'].shift(-1))


Out[124]:
[<matplotlib.lines.Line2D at 0x7f9741af8518>]

In [ ]:


In [ ]:

End of shl_sm


In [ ]:

Start of prediction module: shl_pm


In [ ]:


In [166]:
# 11:29:51~
def predict_k_step_price(df_shl_pm, ccyy_mm, time, k):
    print('month & time  : ', ccyy_mm, time)
    print()
#     df_shl_pm_k = pd.DataFrame() # initialize prediction dataframe
    for sec in range(0, k):
        print('delta second(s) : ', sec)
        current_time  = get_future_n_sec_time_as_str(time, sec)
        print('current_time  : %s' % current_time)
        previous_time = get_previous_n_sec_time_as_str(current_time, 1)
        print('previous_time : %s' % previous_time)

        previous_pred_les_level = df_shl_pm[(df_shl_pm['ccyy-mm'] == global_parm_ccyy_mm) \
                                            & (df_shl_pm['time'] ==previous_time)].iloc[0]['pred_les_level']
        print('     previous_pred_les_level : %f' % previous_pred_les_level)
        
        previous_pred_les_trend = df_shl_pm[(df_shl_pm['ccyy-mm'] == global_parm_ccyy_mm) \
                                            & (df_shl_pm['time'] ==previous_time)].iloc[0]['pred_les_trend']
        print('     previous_pred_les_trend : %f' % previous_pred_les_trend)


        print('---- Pre-Process ---')
        ############ use predicted value for boost-trap
        previous_pred_price = df_shl_pm[(df_shl_pm['ccyy-mm'] == global_parm_ccyy_mm) \
                                            & (df_shl_pm['time'] == previous_time)].iloc[0]['pred_price']
        # pre-process: ccyy-mm-hh:mm:ss
        current_datetime = global_parm_ccyy_mm + ' ' + current_time
#         current_price4pm = df_history_ts_process['bid-price'][i] -  global_parm_base_price
        current_price4pm = previous_pred_price -  global_parm_base_price
        print('#### current_datetime   : %s ####' %  current_datetime)
        print('#### previous_pred_price: %s ####' %  previous_pred_price)
        print('#### current_price4pm   : %d ####' % current_price4pm)

        # get Seasonality-Index
        current_si = fetech_si(global_parm_ccyy_mm
                                             ,current_time
                                             ,df_parm_si)
        print('#### current_si         : %0.10f ####' %  current_si)
        # get de-seasoned price: price4pmsi
        current_price4pmsi = current_price4pm / current_si
        print('#### current_price4pmsi : %0.10f ####' % current_price4pmsi)


        current_pred_les_level = global_parm_alpha * current_price4pmsi \
                                    + (1 - global_parm_alpha) * (previous_pred_les_level + previous_pred_les_trend)
        print('     current_pred_les_level  : %f' % current_pred_les_level)
        current_pred_les_trend = global_parm_beta * (current_pred_les_level - previous_pred_les_level) \
                                    + (1 - global_parm_beta) * previous_pred_les_trend
        print('     current_pred_les_trend  : %f' % current_pred_les_trend)
        current_pred_les = current_pred_les_level + current_pred_les_trend
        current_pred_les_misc = 0
        current_pred_price = (current_pred_les + current_pred_les_misc) * current_si \
                                + global_parm_base_price
        current_pred_price_rounded = round(current_pred_price/100, 0) * 100
        current_pred_dynamic_increment = global_parm_dynamic_increment
        current_pred_set_price_rounded = current_pred_price_rounded + current_pred_dynamic_increment 
#         write results to shl_pm dataframe
        df_shl_pm_current = {
                             'ccyy-mm' : global_parm_ccyy_mm
                            ,'time' : current_time
                            ,'bid' : previous_pred_price
                            ,'datetime' : current_datetime
                            ,'price4pm' : current_price4pm
                            ,'si' : current_si
                            ,'price4pmsi' :  current_price4pmsi
                            ,'pred_les_level' : current_pred_les_level
                            ,'pred_les_trend' : current_pred_les_trend
                            ,'current_pred_les' : current_pred_les
                            ,'pred_les_misc' : current_pred_les_misc
                            ,'pred_price' : current_pred_price
                            ,'pred_price_rounded' : current_pred_price_rounded
                            ,'pred_dynamic_increment' : current_pred_dynamic_increment # +200 or + 300
                            ,'pred_set_price_rounded' : current_pred_set_price_rounded
                            }
        print('---------------------------')
        df_shl_pm =  df_shl_pm.append(df_shl_pm_current, ignore_index=True)
        
    return df_shl_pm

In [178]:
df_shl_pm_new = predict_k_step_price(df_shl_pm, global_parm_ccyy_mm, '11:29:51', 10)


month & time  :  2017-07 11:29:51

delta second(s) :  0
current_time  : 11:29:51
previous_time : 11:29:50
     previous_pred_les_level : 570.643404
     previous_pred_les_trend : 8.749380
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:51 ####
#### previous_pred_price: 91518.9267663 ####
#### current_price4pm   : 1119 ####
#### current_si         : 2.0011852710 ####
#### current_price4pmsi : 559.6317255166 ####
     current_pred_les_level  : 566.699621
     current_pred_les_trend  : 5.826464
---------------------------
delta second(s) :  1
current_time  : 11:29:52
previous_time : 11:29:51
     previous_pred_les_level : 566.699621
     previous_pred_les_trend : 5.826464
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:52 ####
#### previous_pred_price: 91544.7307684 ####
#### current_price4pm   : 1145 ####
#### current_si         : 2.0661036070 ####
#### current_price4pmsi : 554.5369382596 ####
     current_pred_les_level  : 560.971078
     current_pred_les_trend  : 3.165636
---------------------------
delta second(s) :  2
current_time  : 11:29:53
previous_time : 11:29:52
     previous_pred_les_level : 560.971078
     previous_pred_les_trend : 3.165636
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:53 ####
#### previous_pred_price: 91564.5648987 ####
#### current_price4pm   : 1165 ####
#### current_si         : 2.1682095660 ####
#### current_price4pmsi : 537.5702224319 ####
     current_pred_les_level  : 547.072203
     current_pred_les_trend  : -0.763893
---------------------------
delta second(s) :  3
current_time  : 11:29:54
previous_time : 11:29:53
     previous_pred_les_level : 547.072203
     previous_pred_les_trend : -0.763893
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:54 ####
#### previous_pred_price: 91583.5109032 ####
#### current_price4pm   : 1184 ####
#### current_si         : 2.2903489060 ####
#### current_price4pmsi : 517.1748724040 ####
     current_pred_les_level  : 527.594967
     current_pred_les_trend  : -5.073106
---------------------------
delta second(s) :  4
current_time  : 11:29:55
previous_time : 11:29:54
     previous_pred_les_level : 527.594967
     previous_pred_les_trend : -5.073106
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:55 ####
#### previous_pred_price: 91595.7573724 ####
#### current_price4pm   : 1196 ####
#### current_si         : 2.4136021070 ####
#### current_price4pmsi : 495.8387171376 ####
     current_pred_les_level  : 505.382420
     current_pred_les_trend  : -9.019889
---------------------------
delta second(s) :  5
current_time  : 11:29:56
previous_time : 11:29:55
     previous_pred_les_level : 505.382420
     previous_pred_les_trend : -9.019889
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:56 ####
#### previous_pred_price: 91597.0216518 ####
#### current_price4pm   : 1198 ####
#### current_si         : 2.5506970550 ####
#### current_price4pmsi : 469.6840220246 ####
     current_pred_les_level  : 479.226068
     current_pred_les_trend  : -12.965986
---------------------------
delta second(s) :  6
current_time  : 11:29:57
previous_time : 11:29:56
     previous_pred_les_level : 479.226068
     previous_pred_les_trend : -12.965986
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:57 ####
#### previous_pred_price: 91588.2882165 ####
#### current_price4pm   : 1189 ####
#### current_si         : 2.7053908880 ####
#### current_price4pmsi : 439.5994019939 ####
     current_pred_les_level  : 449.135070
     current_pred_les_trend  : -16.909446
---------------------------
delta second(s) :  7
current_time  : 11:29:58
previous_time : 11:29:57
     previous_pred_les_level : 449.135070
     previous_pred_les_trend : -16.909446
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:58 ####
#### previous_pred_price: 91568.3392649 ####
#### current_price4pm   : 1169 ####
#### current_si         : 2.7745487590 ####
#### current_price4pmsi : 421.4520509342 ####
     current_pred_les_level  : 425.305412
     current_pred_les_trend  : -18.502997
---------------------------
delta second(s) :  8
current_time  : 11:29:59
previous_time : 11:29:58
     previous_pred_les_level : 425.305412
     previous_pred_les_trend : -18.502997
---- Pre-Process ---
#### current_datetime   : 2017-07 11:29:59 ####
#### previous_pred_price: 91527.6931343 ####
#### current_price4pm   : 1128 ####
#### current_si         : 2.9291830210 ####
#### current_price4pmsi : 385.3269413929 ####
     current_pred_les_level  : 393.008028
     current_pred_les_trend  : -21.679498
---------------------------
delta second(s) :  9
current_time  : 11:30:00
previous_time : 11:29:59
     previous_pred_les_level : 393.008028
     previous_pred_les_trend : -21.679498
---- Pre-Process ---
#### current_datetime   : 2017-07 11:30:00 ####
#### previous_pred_price: 91486.6892247 ####
#### current_price4pm   : 1087 ####
#### current_si         : 3.0710424510 ####
#### current_price4pmsi : 354.1759002134 ####
     current_pred_les_level  : 360.310845
     current_pred_les_trend  : -24.216594
---------------------------

In [181]:
df_shl_pm_new.tail(11)


Out[181]:
bid ccyy-mm current_pred_les datetime pred_dynamic_increment pred_les_level pred_les_misc pred_les_trend pred_price pred_price_rounded pred_set_price_rounded price4pm price4pmsi si time
50 91500.000000 2017-07 579.392785 2017-07 11:29:50 300.0 570.643404 0.0 8.749380 91518.926766 91500.0 91800.0 1101.000000 569.601044 1.932932 11:29:50
51 91518.926766 2017-07 572.526085 2017-07 11:29:51 300.0 566.699621 0.0 5.826464 91544.730768 91500.0 91800.0 1119.926766 559.631726 2.001185 11:29:51
52 91544.730768 2017-07 564.136714 2017-07 11:29:52 300.0 560.971078 0.0 3.165636 91564.564899 91600.0 91900.0 1145.730768 554.536938 2.066104 11:29:52
53 91564.564899 2017-07 546.308310 2017-07 11:29:53 300.0 547.072203 0.0 -0.763893 91583.510903 91600.0 91900.0 1165.564899 537.570222 2.168210 11:29:53
54 91583.510903 2017-07 522.521861 2017-07 11:29:54 300.0 527.594967 0.0 -5.073106 91595.757372 91600.0 91900.0 1184.510903 517.174872 2.290349 11:29:54
55 91595.757372 2017-07 496.362531 2017-07 11:29:55 300.0 505.382420 0.0 -9.019889 91597.021652 91600.0 91900.0 1196.757372 495.838717 2.413602 11:29:55
56 91597.021652 2017-07 466.260081 2017-07 11:29:56 300.0 479.226068 0.0 -12.965986 91588.288217 91600.0 91900.0 1198.021652 469.684022 2.550697 11:29:56
57 91588.288217 2017-07 432.225624 2017-07 11:29:57 300.0 449.135070 0.0 -16.909446 91568.339265 91600.0 91900.0 1189.288217 439.599402 2.705391 11:29:57
58 91568.339265 2017-07 406.802414 2017-07 11:29:58 300.0 425.305412 0.0 -18.502997 91527.693134 91500.0 91800.0 1169.339265 421.452051 2.774549 11:29:58
59 91527.693134 2017-07 371.328530 2017-07 11:29:59 300.0 393.008028 0.0 -21.679498 91486.689225 91500.0 91800.0 1128.693134 385.326941 2.929183 11:29:59
60 91486.689225 2017-07 336.094250 2017-07 11:30:00 300.0 360.310845 0.0 -24.216594 91431.159710 91400.0 91700.0 1087.689225 354.175900 3.071042 11:30:00

In [182]:
df_shl_pm.tail()


Out[182]:
bid ccyy-mm current_pred_les datetime pred_dynamic_increment pred_les_level pred_les_misc pred_les_trend pred_price pred_price_rounded pred_set_price_rounded price4pm price4pmsi si time
46 91200.0 2017-07 500.214563 2017-07 11:29:46 300.0 501.770041 0.0 -1.555478 91183.646885 91200.0 91500.0 801.0 510.639719 1.568621 11:29:46
47 91300.0 2017-07 537.151994 2017-07 11:29:47 300.0 531.502619 0.0 5.649376 91280.676465 91300.0 91600.0 901.0 548.924652 1.641391 11:29:47
48 91400.0 2017-07 570.579848 2017-07 11:29:48 300.0 559.731077 0.0 10.848771 91396.984827 91400.0 91700.0 1001.0 572.303719 1.749071 11:29:48
49 91400.0 2017-07 572.515368 2017-07 11:29:49 300.0 563.334921 0.0 9.180447 91423.650660 91400.0 91700.0 1001.0 559.300750 1.789735 11:29:49
50 91500.0 2017-07 579.392785 2017-07 11:29:50 300.0 570.643404 0.0 8.749380 91518.926766 91500.0 91800.0 1101.0 569.601044 1.932932 11:29:50

In [186]:
plt.figure(figsize=(12,6))
plt.plot(df_shl_pm_new['bid'])
plt.plot(df_shl_pm_new['pred_price'].shift(1))
# plt.plot(df_shl_pm_k['pred_price'].shift(-1))


Out[186]:
[<matplotlib.lines.Line2D at 0x7f97412ba860>]

In [187]:
plt.figure(figsize=(12,6))
plt.plot(df_shl_pm['bid'])
# plt.plot(df_shl_pm['pred_price'])
plt.plot(df_shl_pm['pred_price'].shift(1))
# plt.plot(df_shl_pm['pred_price'].shift(-1))


Out[187]:
[<matplotlib.lines.Line2D at 0x7f9741228a20>]

In [ ]:


In [ ]:


In [ ]:


In [ ]:

End of prediction module: shl_pm


In [ ]:

[1] Import useful reference packages


In [ ]:
# from __future__ import print_function, division
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
import pandas as pd
import operator
from scipy import interp
from itertools import cycle
from sklearn import svm
from sklearn.utils.validation import check_random_state
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.preprocessing import StandardScaler

from sklearn.ensemble import GradientBoostingRegressor
from sklearn.ensemble import RandomForestRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.ensemble import BaggingRegressor
from sklearn.linear_model import LinearRegression
from sklearn.neighbors import KNeighborsRegressor
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier

from sklearn.metrics import roc_curve, auc
from statsmodels.graphics.mosaicplot import mosaic
print(__doc__)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


The End